home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-21 | 6.2 KB | 228 lines | [TEXT/edF6] |
- *******************************
- **Fantasm V4 PowerPC demo #1
- **A PowerPC assembly language example program just for fun.
- **Opens a window and runs various graphical tests
- **Runs in any colour mode.
- **File:PPC_graph_demo.s
- **Date: 3rd Dec.95
- **©Lightsoft 1995.
-
- **Normal Mac init stuff
-
- param1: reg r3 *Set up the names of the regs used for parameter passing
- param2: reg r4
- param3: reg r5
- param4: reg r6
- bss: reg r30 *The register we use for global data
- **Note that if calling system calls, r31 must remain intact, so we simply don't use it.
- ; title "demo"
- ; input "None."
- ; output "None."
- ppc_graph_demo:
-
- ENTRY *Prog starts here
- start_up *save all the regs and set up r30 for global
- la r3,qd(`bss) *get the address of the QD array into r3
- addic r3,r3,206-4
- Xcall InitGraf *Init managers
- Xcall InitFonts
- Xcall InitWindows
- Xcall InitMenus
- Xcall TEInit
- li `param1,0
- Xcall InitDialogs
- Xcall InitCursor
-
- **Open our window and copy its viewrect.
- bl graph_demo_init *initialise and open a window and get its viewrect into viewrect_1(bss)
- **now the drawing
- **lets start with some nice horizontal lines
- **First lets set the foreground colour to white
- lwz `param1,white(rtoc)
- Xcall RGBForeColor *That should do it
- **now a simple horiz test line - draw r22 white lines
- la r3,viewrect_1(`bss) *top,left,bott,right
- lhz r20,2(r3) *left of window
- lhz r21,6(r3) *right of window
- lhz r22,4(r3) *bottom
-
- **use MoveTo and LineTo to draw the line
- line_loop:
- bl draw_line *draw a line
- subic. r22,r22,1 *up 1 line
- bne- line_loop *and if line y isn't zero draw another line.
-
- **now we'll do the same, but change the colours dynamically this time and
- **fill the window 50 times
- li r26,50 *do it all 50 times
- outer_loop:
- **reset the x and y's
- la r3,viewrect_1(`bss) *top,left,bott,right
- lhz r20,2(r3) *left of window
- lhz r21,6(r3) *right of window
- lhz r22,4(r3) *bottom
-
- **Draw line and alter the components of the colour
- line_loop_2:
- bl draw_line *draw this line
- lwz r23,white1(rtoc) *r23 points to our colour that we are altering
-
- lhz r24,(r23) *get the red value
- subic r24,r24,64 *subtract 64 from the red
- sth r24,(r23) *save the new colour back in memory
-
- lhz r24,2(r23) *get the green value
- subic r24,r24,32 *subtract 32 from the green
- sth r24,2(r23) *save the new colour back in memory
-
- lhz r24,4(r23) *get the blue value
- subic r24,r24,128 *subtract 128 from the blue
- sth r24,4(r23) *save the new colour back in memory
-
- lwz `param1,white1(rtoc)
- Xcall RGBForeColor *Set new forground colour to white1
-
- subic. r22,r22,1 *up 1 line
- bne line_loop_2 *and if not top of window (line=0) draw next line in new colour.
-
- subic. r26,r26,1 *do it all r26 times
- bne outer_loop
-
-
- bl clear_window *clear the window out by scrolling
-
- **now lets draw a circles
- li r28,3 *do the zoomy circles 3 times
- rgb_zooms:
- lwz `param1,red(rtoc)
- Xcall RGBForeColor *Set new forground colour
- bl draw_circles *draw a zoomy circle in red.
-
- lwz `param1,green(rtoc)
- Xcall RGBForeColor *Set new forground colour
- bl draw_circles *draw a zoomy circle in green
-
- lwz `param1,blue(rtoc)
- Xcall RGBForeColor *Set new forground colour
- bl draw_circles *draw a zoomy circle in blue
- subic. r28,r28,1
- bne rgb_zooms
- tidy_up *restore all the regs back to how they were before this prog started.
- blr *bye bye - end of program.
-
-
- *****************
- **Drawing subroutine follow
- draw_circles:
- mflr r29 *save return addr.
- **First reduce our viewrect_2 down to a small size
- la r20,viewrect_1(`bss) *copy this rect
- la r22,viewrect_2(`bss) *to this rect whilst making it smaller
- lhz r21,(r20)
- addic. r21,r21,100
- sth r21,(r22) *top+100
-
- lhz r21,2(r20)
- addic. r21,r21,100
- sth r21,2(r22) *left+100
-
- lhz r21,4(r20)
- subic. r21,r21,100
- sth r21,4(r22) *bottom-100
-
- lhz r21,6(r20)
- subic. r21,r21,100
- sth r21,6(r22) *right-100
-
- li r26,100 *loop count
- **Now drow r26 circles, each slightly larger than the last
- circles:
- la `param1,viewrect_2(`bss) *top,left,bott,right
- Xcall PaintOval *simple?
-
- la r20,viewrect_2(`bss)
- lhz r21,(r20)
- subic. r21,r21,2
- sth r21,(r20) *top-2
-
- lhz r21,2(r20)
- subic. r21,r21,2
- sth r21,2(r20) *left-2
-
- lhz r21,4(r20)
- addic. r21,r21,2
- sth r21,4(r20) *bottom+2
-
- lhz r21,6(r20)
- addic. r21,r21,2
- sth r21,6(r20) *right+2
-
- subic. r26,r26,1
- bne circles
- mtlr r29
- blr
-
- *************************************************
- **Draws a horizontal line in the forground colour.
- **Needs start x in r20, end x in r21 and y in r22
- draw_line:
- mflr r29
- mr `param1,r20
- mr `param2,r22
- Xcall MoveTo
- mr `param1,r21
- mr `param2,r22
- Xcall LineTo
- mtlr r29
- blr *easy innit?
- ************************************************************************************
- **Clears our window by first scrolling diagonally, and then virtically (virtically?).
- clear_window:
- mflr r29 *this is a subroutine, so save return address.
- **First lets set the foreground colour to white
- lwz `param1,white(rtoc)
- Xcall RGBForeColor *That should do it
-
- *extern pascal void ScrollRect(const Rect *r, short dh, short dv, RgnHandle updateRgn)
- **Get height/2 in r22
- la r20,viewrect_1(`bss)
- lhz r22,4(r20) *bottom for use as a loop counter
-
- **Scroll diagonally
- scroll_diag_loop:
- la `param1,viewrect_1(`bss) *top,left,bott,right
- li `param2,1 *dh = delta horizontal = 1 pixel
- li `param3,1 *dv = delta vertical = 1 pixel = diagonal scroll.
- li `param4,0 *updatergn
- Xcall ScrollRect *scroll by 1 pixels
- subic. r22,r22,1 *Decrement loop count
- bne scroll_diag_loop *and branch if not zero to scroll again
-
- la r20,viewrect_1(`bss)
- lhz r22,4(r20) *bottom for use as loop counter
- **Scroll down
- scroll_down_loop:
- la `param1,viewrect_1(`bss) *top,left,bott,right
- li `param2,0 *dh
- li `param3,1 *dv
- li `param4,0 *updatergn
- Xcall ScrollRect *scroll by 1 pixel
- subic. r22,r22,1 *Decrement loop count
- bne scroll_down_loop *and branch if not zero to scroll again
-
- mtlr r29 *get return address
- blr
- *********************************************************
- **Predefined Data that goes in the data section
- **Our colours defined as red,green,blue strengths.
- white: dc.h 0xffff,0xffff,0xffff
- white1: dc.h 0xffff,0xffff,0xffff
- red: dc.h 0xffff,0,0
- green: dc.h 0,0xffff,0
- blue: dc.h 0,0,0xffff
- ****
- *********************************************************
- **The declarations.
- global ppc_graph_demo
- extern graph_demo_init *External initialisation subroutine in graph_demo_init.s
-